
//默认导出  一个文件只能导出一次
//export default render

//命名导出
export const ele = <h1 id="box" className='tit'>
<div>
  456
  <li>list</li>
</div>  
</h1>
console.log(ele);
const render = (element, container)=>{
  const{type,props} = element;
  // 创建元素
  const ele = document.createElement(type);
  // 遍历属性
  Object.keys(props).forEach(attr =>{
    if(attr == 'children'){
      if(typeof props['children'] == 'string'){
        ele.innerText = props['children']
      }else if(props['children'] instanceof Array){
        props['children'].forEach(elem=>{
          if(typeof elem == 'string'){
            const txtNode = document.createTextNode(elem);
            ele.appendChild(txtNode);

          }else{
            render(elem,ele)
          }
        })
      }else{
        render(props['children'],ele)

      }
    }else{
      ele[attr] = props[attr]
    }
  })
  // 容器中添加元素
  container.appendChild(ele);
}
render(ele,document.getElementById('root'))
